/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-01-18
 * Time:14:44
 */
public class Computer{
    public void powerOn() {
        System.out.println("电脑开机");
    }

    //因为鼠标类和键盘类都实现了USB接口，所以它们都能向上转型传参给usb
    public void useService(USB usb) {
        usb.openDevice();
        if(usb instanceof Mouse) {
            Mouse mouse = (Mouse) usb;  //向下转型，使用鼠标类特有的方法
            mouse.click();
        } else if (usb instanceof Keyboard) {
            Keyboard keyboard = (Keyboard) usb;
            keyboard.input();
        }
        usb.closeDevice();
    }

    public void powerOff() {
        System.out.println("电脑关机");
    }
}
